<?php

namespace app\api\controller\v1;
use app\api\model\Account as AccountModel;
use app\lib\exception\account\AccountException;
use think\facade\Request;
class Account
{

    /**
     * cookie设置
     * @param('id','待更新的账号','require|number|min:1')
     * @auth('cookie设置','账号管理')
     */
    public function setCookie($id)
    {
        $params = Request::patch();
        if(!key_exists("cookie",$params)) throw new AccountException(['msg' => 'cookie参数需要传入']);
        $account = AccountModel::get($id);
        if (!$account) throw new AccountException(['msg' => 'id为' . $id . '的账号不存在']);

        $account->save(["cookie" => $params["cookie"]]);
        return writeJson(201, [], 'cookie更新成功！');
    }
}
